<template>
  <div class="contioner">
    <div ref="myChart" :style="{ width: '100%', height: '100%' }"></div>
  </div>
</template>
      
  <script lang="ts" setup>
import * as echarts from 'echarts'
import { Message } from '@arco-design/web-vue'
import { ref, reactive, onMounted, watch } from 'vue'
//引入封装post
import { post } from '@/api/http'
import dayjs from 'dayjs'
//getlist初始化接口参数
let query: any = reactive({
  beginDate: dayjs().format('YYYY-MM'), //当月日期
    planOrderCode: localStorage.getItem('firmId') || '',
})

const option = ref({
  title: {
    text: '各织厂在岗率走势图',
  },
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      type: 'shadow',
    },
  },
  // legend: {
  //   // left: "92%",
  //   // top: "18%",
  //   align: 'left',
  //   data: ['定编人数', '在编人数', '缺编人数', '在岗率'],
  // },
  grid: {
    left: '3%',
    right: '3%',
    bottom: '3%',
    containLabel: true,
  },
  xAxis: {
    type: 'category',
    axisTick: { show: false },
    data: ['一厂', '二厂', '三厂', '四厂', '五厂'],
  },
  yAxis: {
    type: 'value',
  },
  series: [
    {
      name: '定编人数',
      type: 'bar',
      data: [320, 332, 301, 334, 390],
      label: { show: true, position: 'top', distance: 10, formatter: '{c}%' },
    },
    {
      name: '在编人数',
      type: 'bar',
      data: [150, 232, 201, 154, 190],
      label: { show: true, position: 'top', distance: 10, formatter: '{c}%' },
    },
    {
      name: '缺编人数',
      type: 'bar',
      data: [98, 77, 101, 99, 40],
      label: { show: true, position: 'top', distance: 10, formatter: '{c}%' },
    },
    {
      name: '在岗率',
      type: 'bar',
      data: [98, 77, 101, 99, 40],
      label: { show: true, position: 'top', distance: 10, formatter: '{c}%' },
    },
  ],
})

//初始化
onMounted(async () => {
  selectJt()
    // const state = states()
  // state.setOption(option.value)
})
const myChart: any = ref()
const states = () => {
  return echarts.init(myChart.value)
}
function selectJt() {
  post({
    url: 'org/report/factoryEntryRate',
    data: {
      firmId: query.planOrderCode, //公司ID
      monthDate: query.beginDate, //日期时间
    },
  }).then((res: any) => {
    if (res.code == 200) {
      option.value.xAxis.data = res.data.firmData.map((v: any) => {
        return v.firm
      })
      option.value.series[0].data = res.data.firmData.map((v: any) => {
        return v.quotaNumber
      })
      option.value.series[1].data = res.data.firmData.map((v: any) => {
        return v.entryNumber
      })
      option.value.series[2].data = res.data.firmData.map((v: any) => {
        return v.lackOfNumber
      })
      option.value.series[3].data = res.data.firmData.map((v: any) => {
        return v.entryRate
      })
      const state = states()
      state.setOption(option.value)
    } else {
      Message.error(res.message)
    }
  })
}
</script>
  <script lang="ts">
export default defineComponent({
  name: 'ChartOfTheWorkingRateOfEachTextileFactory',
})
</script>
  <style scoped>
.contioner {
  width: 100%;
  height: 100%;
  background: #fff;
  padding: 10px;
}

:deep(.ag-cell) {
  border-right: 1px solid #dde2eb;
}

:deep(.ag-header-cell) {
  border-right: 1px solid #dde2eb;
}

:deep(.ag-cell-value) {
  user-select: initial;
  -moz-user-select: text;
  -ms-user-select: text;
  -webkit-user-select: text;
}
</style>
      